<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ContactForm
 *
 * @author ziad
 */
class ImageForm extends sfForm{
    
    private $mime_types, $max_size;
    public $f;
    public function __construct($maxsize = NULL, $types = NULL, $defaults = array(), $options = array(), $CSRFSecret = null) {
        parent::__construct($defaults, $options, $CSRFSecret);
        if($maxsize ==NULL){
            $this->max_size = 100000000;
        }
        else{
            $this->max_size = $maxsize;
        }
//        if($types == NUll){
            $this->mime_types = array ('image/jpeg','image/pjpeg','image/png','image/x-png','image/gif');
//        }
//        else{
//            $this->mime_types = $types;
//        }
        
    }
    public function configure(){
        
        $fileValidator = new sfValidatorFile();
        $fileValidator->setOption('mime_types', array ('image/jpeg','image/pjpeg','image/png','image/x-png','image/gif') );
        $fileValidator->setOption('max_size', $this->max_size);
        $fileValidator->setMessage('max_size', 'file too big');
        $fileValidator->setMessage('mime_types', 'file type not supported');
        
        $this->setWidgets(array(
            'name'=>new sfWidgetFormInput(),
            'file'=>new sfWidgetFormInputFile(array(), array('class'=>'fileButton'))
            ));
        $this->setValidators(array(
            'name'=>new sfValidatorString(array('max_length' => 30)),
            'file'=> $fileValidator
            ));
        $this->getWidgetSchema()->setNameFormat("image[%s]"  );
        $this->getWidgetSchema()->setAttribute('class', 'imgForm');
        $this->getWidgetSchema()->setAttribute('status', 'empty');
        
    }
}